package com.smart.lab.utils.net;

/**
 * Created by liuyan on 2019/2/28.
 */

import android.content.Context;


import com.smart.lab.utils.net.listener.HttpResponseListener;
import com.smart.lab.utils.net.listener.UploadListener;

import java.io.File;
import java.util.List;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;

public class ItheimaHttp {
    public ItheimaHttp() {
    }

    public static final void init(Context context, String httpBaseUrl) {
        HttpHelper.setBaseUrl(httpBaseUrl);
    }

    public static <T> Call getAsync(String apiUrl, HttpResponseListener<T> httpResponseListener) {
        return HttpHelper.getAsync(apiUrl, (Map) null, (Map) null, httpResponseListener);
    }

    public static <T> Call postAsync(String apiUrl, HttpResponseListener<T> httpResponseListener) {
        return HttpHelper.postAsync(apiUrl, (Map) null, (Map) null, httpResponseListener);
    }

    public static <T> Call send(Request request, HttpResponseListener<T> httpResponseListener) {
        return RequestMethod.GET.equals(request.getRequestMethod()) ? HttpHelper.getAsync(request.getApiUlr(), request.getHeaderMap(), request.getParamsMap(), httpResponseListener) : HttpHelper.postAsync(request.getApiUlr(), request.getHeaderMap(), request.getParamsMap(), httpResponseListener);
    }

    public static <T> Call<ResponseBody> sendPostWithBody(Request request, String body, HttpResponseListener<T> httpResponseListener) {
        return HttpHelper.postAsyncWithBody(request.getApiUlr(), body, httpResponseListener);
    }


    public static <T> Call upload(Request request, UploadListener uploadListener) {
        return HttpHelper.upload(request, uploadListener);
    }

    public static <T> Call uploadMultiFile(String url,Map<String, String> params,List<File> fileList, HttpResponseListener<T> httpResponseListener) {
        return HttpHelper.uploadMultiPart(url,params,fileList,httpResponseListener);
    }

    public static Request newRequest(String apiUlr, RequestMethod method) {
        return new Request(apiUlr, method);
    }

    public static Request newPostRequest(String apiUlr) {
        return new Request(apiUlr, RequestMethod.POST);
    }

    public static Request newUploadRequest(String uploadFileUrl, RequestMethod method) {
        return new Request(uploadFileUrl, method);
    }

    public static Request newGetRequest(String apiUlr) {
        return new Request(apiUlr, RequestMethod.GET);
    }

    public static void setDebug(boolean isDebug) {
        L.isDebug = isDebug;
    }
}
